#include "library.h"
#include <torch/script.h> // One-stop header.
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include "classifier.cpp"
#include "dose_adjust.cpp"
#include "enhancement.cpp"
#include <ctime>
#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmdata/dctk.h"
#include <vector>
#include <fstream>
#include <stdio.h>
#include <string.h>
#include <iostream>
typedef unsigned short WORD;//WORD表示16位无符号数

int GetPicAlgorithmVerInfo(char * verStr)
{
    strcpy(verStr, "V1.0.0 Compiled DateTime: Jul 11 10:36:21 2020");
    return 0;
}

int PicProc(WORD * pRawData,char * clsModelPATH,int rawIndex,bool ABFg,int width,int height,int algorithmType,
            int kv,float mA,int autoKvType,int &partType,WORD &newKv,float &newmA)
{
    int flag = 0;
//    FILE * fp = fopen(raw_path, "rb");
//    if(fp == NULL)
//    {
//        printf("can not open the raw image");
//        return 2;
//    }

    Mat image = raw2Mat(pRawData,width,height);
    display(image,"origin");
//    cout << image.type() << endl; // 2 16U
    // 返回分类结果 0未知,1颈椎,2脊椎,3胸椎,4髋部,5四肢
    // 原模型：0颈椎,1手,2踝,3髋,4膝 124输出5 3输出4 0输出2
    partType = classifier(clsModelPATH,image);
//    cout << "分类结果:" << partType << endl;

    newKv = dose_adjust(image,kv,autoKvType,partType);
//    cout << "原电压:" << kv << endl;
//    cout << "调整后电压:" << newKv << endl;
    image = Enhancement(image);
    display(image,"result0");

//    WORD* myptr = (WORD*)image.data;
    WORD * myptr = image.ptr<WORD>(0);

    copy(image.begin<WORD>(),image.begin<WORD>(),pRawData);
//    Mat aaa = raw2Mat(RawData,1024,1024);
//    cv::namedWindow("result", 1);
//    cv::imshow("result", aaa);
//    waitKey(0);
    memcpy(pRawData, myptr, sizeof(WORD)*1024*1024);

    return flag;
}

int CreateDcm(WORD * pRawData,int kv,float mA,char * number,char * patientName,
        int age,int gender,char * dcmFilePath)
{
//    char uid[100];
//    DcmFileFormat fileformat;
//    DcmMetaInfo *metainfo = fileformat.getMetaInfo();
//    DcmDataset *dataset = fileformat.getDataset();
//    dataset->putAndInsertString(DCM_PatientID, "PatientID");
//    dataset->putAndInsertString(DCM_PatientName, "PatientName");
//    dataset->putAndInsertString(DCM_PatientSex, "M");
//    dataset->putAndInsertString(DCM_PatientBirthDate, "20000302");

}
